package com.example.secondhandsysapi.Service;

import com.example.secondhandsysapi.Entity.ActionLogInfo;
import com.example.secondhandsysapi.Mapper.ActionLogInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.stereotype.Service;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;


@Service
public class ActionLogInfoServiceImpl implements ActionLogInfoService {

    @Autowired
    private ActionLogInfoMapper actionLogInfoMapper;
    @Autowired
    private WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter webMvcAutoConfigurationAdapter;


    @Override
    public Integer deleteByID(Integer act_id) {
        return actionLogInfoMapper.deleteByID(act_id);
    }


    @Override
    public List<ActionLogInfo> getAllActionLogInfoOutcomeId(String act_outcome, Integer user_id) {
        return actionLogInfoMapper.getAllActionLogInfoOutcomeId(act_outcome, user_id);
    }

    @Override
    public List<ActionLogInfo> getAllActionLogInfoOutcome(String act_outcome) {
        return actionLogInfoMapper.getAllActionLogInfoOutcome(act_outcome);
    }

    @Override
    public List<ActionLogInfo> getAllActionLogInfoUserId(Integer user_id) {
        return actionLogInfoMapper.getAllActionLogInfoUserId(user_id);
    }

    @Override
    public List<ActionLogInfo> getAllActionLogInfoTime(Date act_time) {
        SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
        Date date = new Date();
        try {
            date = sdf.parse(String.valueOf(act_time));
        } catch (Exception e) {
            e.printStackTrace();
        }
        String formatStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
        return actionLogInfoMapper.getAllActionLogInfoTime(formatStr);
    }

    @Override
    public List<ActionLogInfo> getAllActionLogInfo() {
        return actionLogInfoMapper.getAllActionLogInfo();
    }

    @Override
    public List<ActionLogInfo> getAllActionLogInfoOutcomeTime(String act_outcome, Date act_time) {

        return actionLogInfoMapper.getAllActionLogInfoOutcomeTime(act_outcome, act_time);
    }

    @Override
    public List<ActionLogInfo> getAllActionLogInfoUserIdTime(Integer user_id, Date act_time) {
        return actionLogInfoMapper.getAllActionLogInfoUserIdTime(user_id, act_time);
    }

    @Override
    public List<ActionLogInfo> getAllActionLogInfoUserIdOutcomeTime(Integer user_id, String act_outcome, Date act_time) {
        return actionLogInfoMapper.getAllActionLogInfoUserIdOutcomeTime(user_id, act_outcome, act_time);
    }

}


